<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>自定义对话框列表</title>
<link href="../../build/common/base.css" rel="stylesheet">
<script type="text/javascript" src="../../build/common/base.js"></script>
<script type="text/javascript" src="../../build/common/gridList.js"></script>
</head>
<body class="panel-body">
	<div class="panel panel-default search-panel">
		<div class="panel-heading">
			查询条件
			<a 　href="javascript:void(0)" class="pull-right">
				<i class="fa  fa-angle-double-up" toggle-collapse="#searchForm"></i>
			</a>
		</div>
		<div class="panel-body">
			<form id="searchForm" class="form-horizontal">
				<div class="form-group">
					<label class="control-label col-sm-1" for="name_^VLK">名称</label>
					<div class="col-sm-2">
						<input type="text" class="form-control" id="name_^VLK">
					</div>
					<label class="control-label col-sm-1" for="alias_^VLK">别名</label>
					<div class="col-sm-2">
						<input type="text" class="form-control" id="alias_^VLK">
					</div>
					<label class="control-label col-sm-1" for="object_name_^VLK">对象名字</label>
					<div class="col-sm-2">
						<input type="text" class="form-control" id="object_name_^VLK">
					</div>
					<div class="col-sm-3" style="text-align: left;">
						<button type="button" style="margin-left: 50px" class="btn btn-primary fa-search">查询</button>
						<button type="button" style="margin-left: 50px" class="btn btn-primary fa-rotate-left">重置</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<div class="btn-group toolbar">
		<button class="btn btn-outline btn-primary fa-plus" openDialog="新增脚本" url="./custDialogEdit.html">新增</button>
	</div>
	<table ab-grid data-id-field="id" data-url="/form/custDialog/listJson">
		<thead>
			<tr>
				<th data-checkbox="true">ID</th>
				<th data-field="name">名称</th>
				<th data-field="alias">别名</th>
				<th data-field="style" data-formatter="labelFormatter" data-val-text="{'0':'列表','1':'树形'}">显示样式</th>
				<th data-field="system" data-formatter="labelFormatter" 
						data-val-text="{'1':'是','0':'否'}" data-val-style="{'true':'success','false':'danger'}">系统内置</th>
				<th data-field="objName">对象名称</th>
				<th data-field="dsalias" >数据源别名</th>
				<th data-field="createTime" data-formatter="dateTimeFormatter" >创建时间</th>
				<th data-field="id" data-formatter="managerFormatter">管理</th>
			</tr>
		</thead>
	</table>
</body>
</html>
<script type="text/javascript">
	function managerFormatter(value, row, index){
		var bts ="<span class='btn btn-outline btn-primary fa-edit' openDialog='编辑' qtip='编辑' url='./custDialogEdit.html?id="+ row.id +"'></span>";
		if(row.system==0){
			 bts += "<span class='btn btn-outline btn-primary fa  fa-trash' sendAction='删除' qtip='删除'  url='/form/custDialog/remove?id="+row.id+"'></span>";
		}
		 bts += "<span class='btn btn-outline btn-primary fa-caret-square-o-left' qtip='预览' onclick='showDialog(\""+ row.alias+"\")'></span>";
		return bts;
	}
	
	function showDialog(alias) {
		var url = __ctx + '/form/custDialog/getByAlias?alias=' + alias;
		$.ajax({
			url : url,
			type : 'POST',
			dataType : 'json',
			success : function(customDialog) {
				var list = JSON.parse(customDialog.conditionfield);
				var param = {};
				$(list).each(function() {
					if (this.defaultType == "4") {
						param[this.field] = this.comment;
					}
				});

				if($.isEmptyObject(param)){//没有动态传入的字段
					CustUtil.openCustDialog(alias);
					return;
				}
				var url = "../../form/custDialog/paramDialog.html";
				var conf = { height:400,width:600,
					    url:url,
					    title:"设置参数",
					    btn:true,
					    passData:param
					};
				conf.ok = function(index,innerWindow){
				    var data = innerWindow.getResult().map;
				    $.Dialog.close(innerWindow);
				    CustUtil.openCustDialog(alias,data);
				}
				$.Dialog.open(conf); 
			}
		});
	}
</script>